package com.meme.editor.property.value;

import java.util.Vector;

import org.apache.log4j.Logger;

import com.meme.editor.EntityObject;
import com.meme.editor.property.Property;
import com.meme.editor.property.PropertyFactory;
import com.meme.editor.property.PropertyValue;

public class BoolPropertyValue extends PropertyValue 
{
	static Logger logger = Logger.getLogger (BoolPropertyValue.class);
	
	boolean mTheValue;
	
	public BoolPropertyValue (Property property)
	{
		super (property);
	}
	
	@Override
	public String getDefaultControlType ()
	{
		return PropertyFactory.ControlType_SelectList;
	}
	
	@Override
	public Object   getValue ()
	{
		return mTheValue;
	}
	
	@Override
	public String toString ()
	{
		return mTheValue ? "true" : "false";
	}
	
	@Override
	protected boolean modify (Object newValue)
	{
		if ( newValue instanceof Boolean )
		{
			mTheValue = ( (Boolean) newValue ).booleanValue();
			return true;
		}
		else if ( newValue instanceof String )
		{
			mTheValue = Boolean.parseBoolean( (String) newValue );
			return true;
		}
		
		return false;
	}	
	
	@Override
	public String getValueAsString ()
	{
		return toString ();
	}

	@Override
	protected Object   makeLegalValueFromControl (Object[] params)
	{
		int selectIndex = ( (Integer) params[0] ).intValue();
		if ( selectIndex <= 0 )
			return false;
		else
			return true;
	}
	
	@Override
	protected Object[] makeDataForControl ()
	{
		Vector list = new Vector ();
		list.add ("false");
		list.add ("true");

		int selectIndex = mTheValue ? 1 : 0;
		
		Object[] params = new Object[]
		      {
				selectIndex,
				list
		      };
		
		return params;
	}
	
	@Override
	protected boolean _setParameter (String name, Object value)
	{
		return false;
	}
	
}
